package com.example.questionsystem.modules.qu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.questionsystem.modules.qu.entity.Projects;
import com.example.questionsystem.modules.qu.mapper.ProjectsMapper;
import com.example.questionsystem.modules.qu.service.ProjectsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProjectsServiceImpl extends ServiceImpl<ProjectsMapper, Projects> implements ProjectsService {


    @Resource
    private ProjectsMapper projectsMapper;
    @Override
    public void saveProjects(Projects projects) {
        Projects projects1 = projectsMapper.selectOne(new QueryWrapper<Projects>().eq("project_id", projects.getProjectId()));
        if (projects1 != null) {
            int delete = projectsMapper.delete(new QueryWrapper<Projects>().eq("project_id", projects.getProjectId()));
            if (delete == 0) {
                throw new RuntimeException("删除失败");
            }
        }
        projectsMapper.insert(projects);
    }

    @Override
    public List<Projects> getProjectsList() {
        return projectsMapper.selectList(null);
    }

    @Override
    public Projects getById(String id) {
        QueryWrapper<Projects> ProjectsQueryWrapper = new QueryWrapper<>();
      return   projectsMapper.selectOne(ProjectsQueryWrapper.eq("project_id",id));
    }
}